var http = require("../../utils/request.js");
var app = getApp();
Page({
  data: {
    avatarUrl: '../../images/icon/avatar.jpg',
    nickName: '登录',
    topList: [{
      url: '../share/share',
      img: '/images/icon/yue.png',
      text: '余额',
      gold: '0.01'
    }, {
      url: '../share/share',
      img: '/images/icon/jinbi.png',
      text: '奖金',
      gold: '0.00'
    }],
    bottomList: [{
        url: '../share/share',
        img: '/images/icon/fenxiang.png',
        text: '分享二维码',
        number: '(已推荐:20人)'
      }, {
        url: '../myOrder/myOrder',
        img: '/images/icon/dingdan.png',
        text: '我的订单'
      },
      // {
      //     url: '../myPassword/myPassword',
      //     img: '/images/icon/mima.png',
      //     text: '我的密码'
      //   }, {
      //     url: '../share/share',
      //     img: '/images/icon/logout.png',
      //     text: '退出账号'
      // }
    ]
  },
  onGotUserInfo: function(e) {
    var that = this;
    console.log('登录');
    app.getUserInfo();
    console.log(app.globalData.userInfo);
    that.setData({
      avatarUrl: app.globalData.userInfo.avatarUrl,
      nickName: app.globalData.userInfo.nickName,
    })
  },
  onShare: function() {
    console.log('跳转到分享页');
    wx.navigateTo({
      url: '../share/share',
    })
  },
  onLoad: function(options) {
    var that = this;
    // console.log(app.globalData.userInfo);
    // console.log(app.globalData.userInfo.avatarUrl);
    // console.log(app.globalData.userInfo.nickName);
    wx.getSetting({
      success: function(res) {
        if (res.authSetting['scope.userInfo']) {
          //用户已经授权过从缓存中拿userinfo、openid、userid
          app.globalData.userInfo = wx.getStorageSync('userInfo')
          app.globalData.openId = wx.getStorageSync('openId')
          app.globalData.userId = wx.getStorageSync('userId')
          that.setData({
            avatarUrl: app.globalData.userInfo.avatarUrl,
            nickName: app.globalData.userInfo.nickName
          })
        }
      }
    })
  }
})